Skip to content

Conversation

volkmarnissen
Copy link

This fix avoids locked objects when inserting multiple rows to the same table by firing multiple query requests.
The queries can run at the same time and generate locking errors.

Example: msg.payload contains array of objects to insert.
A split node generates an single payload for each of them and passes them to the mysql node.
You might get lock errors, because all values will be executed in paralell

It's better to execute all inserts in one statements and in one transaction.

If the payload, contains an array, all objects in that array will be processed in one transaction.
No split node is required.
if the payload contains an object, it's treated as an array with one entry.

Example topic and payload

msg.topic = "insert into test (date_hour, price) " +
    "select :hour, :price  from dual where not exists( select hour from test where " +
    "hour =:hour);\n"

msg.payload  = [{ date_hour: 1234, price:0.234},{ date_hour: 12345, price:0.235}]
return msg;

@Bacto
Copy link
Contributor

Bacto commented Oct 6, 2025

Hello,

Thank you for this PR, really appreciate that!
With the version 1.0.6, you can now run bulk queries in an easy way:
https://github.com/stackhero-io/node-red-contrib-stackhero-mysql/?tab=readme-ov-file#usage

Here is an example:

msg.topic = 'INSERT INTO `users` (`name`, `age`) VALUES ?';
msg.payload = [[
  [ 'Adrien', 42 ],
  [ 'Romain', 12 ]
]];

return msg;

@Bacto Bacto closed this Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants